package com.bwie.controller;

import com.bwie.pojo.Order;
import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.sevice.OrderService;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * description:
 *
 * @Author caoshuaifeng
 * @Create 2025/3/31 08:52
 * @Version 1.0
 */
@RestController
@RequestMapping("/order/index")
public class IndexController {

    @Autowired
    OrderService orderService;

    @Autowired
    TbUserService tbUserService;

    @PostMapping("/joinGroup")
    public R joinGroup(@RequestBody @Validated Order order){
      return orderService.joinGroup(order);

    }


    @PostMapping("/viewGroup")
    public String viewGroup(@Validated Model model) {
        Order order = new Order();
        order.setUserId(1L);
        order.setGroupId(101L);
        model.addAttribute("Order", order);
        return "viewGroup";
    }
 //)实现抽奖概率列表功能（10分）
    @GetMapping("/getPrizeList")
    public R getPrizeList(){
        return orderService.getPrizeList();
    }

    //实现抽奖概率新增功能
    @PostMapping("/addPrize")
    public R addPrize(@RequestBody Order order){
        return orderService.addPrize(order);

    }
    //实现抽奖概率修改功能
    @PostMapping("/updatePrize")
    public R updatePrize(@RequestBody Order order){
        return orderService.updatePrize(order);
    }

    //实现抽奖概率移除功能
    @PostMapping("/deletePrize/{id}")
    public R deletePrize(@PathVariable("id") Integer id){
        return orderService.deletePrize(id);
    }


    @PostMapping("/selectAll")
    public R selectAll(){
        return tbUserService.selectAll();
    }

    @PostMapping("/addUser")
    public R addUser(@RequestBody TbUser tbUser){
        return tbUserService.addUser(tbUser);
    }

    @PostMapping("/deleteUser")
    public R deleteUser(@RequestBody TbUser tbUser){
        return tbUserService.deleteUser(tbUser);
    }

    public R updateUser(@RequestBody TbUser tbUser){
        return tbUserService.updateUser(tbUser);
    }




}
